package com.alpha.bom;

/**
 * This class is used to represent the user object
 * 
 * @author John Gabriel Canoy
 * @version 1.0
 * @since JDK1.7
 */
public abstract class User {
	private int userId;
	private String password;
	private String firstName;
	private String lastName;
	private String userType;
	
	/**
	 * This is used to retrieve the ID number of the user.
	 * @return The user's ID number
	 */
	public int getUserId() {
		return userId;
	}
	
	/**
	 * This is used to set the ID number of the user with the one indicated.
	 * @param userId Student's ID number to set
	 */
	public void setUserId(int userId) {
		this.userId = userId;
	}
	
	/**
	 * This methods retrieves the current password of the user.
	 * @return String value of the password
	 */
	public String getPassword() {
		return password;
	}
	
	/**
	 * This methods changes the current password of the user with the one indicated.
	 * @param password the new password of the user
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	/**
	 * This is used to retrieve the first name of the user.
	 * @return The student's first name
	 */
	public String getFirstName() {
		return firstName;
	}
	
	/**
	 * This is used to set the first name of the user with the one indicated.
	 * @param firstName user's first name to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	/**
	 * This is used to retrieve the last name of the user.
	 * @return The user's last name
	 */
	public String getLastName() {
		return lastName;
	}
	
	/**
	 * This is used to set the last name of the user with the one indicated.
	 * @param lastName user's last name to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	/**
	 * This sets the user type with the one indicated.
	 * @param userType the userType to set
	 */
	public void setUserType(String userType) {
		this.userType = userType;
	}

	/**
	 * This is used to retrieve the user type.
	 * @return the userType
	 */
	public String getUserType() {
		return userType;
	}

	/**
	 * This methods verifies if the username and password entered by the user are correct.
	 * @param username Login name of the user
	 * @param password Login password of the user
	 * @return true if the username and password matches with the correct ones.
	 */
	public boolean validateLogin(int userId, String password) {
		boolean success = false;
		success = userId == this.getUserId() && password.equals(this.getPassword());
		return success;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + userId;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (userId != other.userId)
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "User [userId=" + userId + ", firstName=" + firstName
				+ ", lastName=" + lastName + "]";
	}
}
